
package model.xmlconvert;

import nu.xom.Attribute;
import nu.xom.Element;

public class ModelRectangleFlowChartComponent extends ModelFlowChartComponent {

	private ModelRectangleValidation validator = new ModelRectangleValidation();
	
	public ModelRectangleFlowChartComponent(String label) {
		super(label);
	}

	@Override
	public Element getXML() {
		
		Element e = new Element("rectangle");
		e.addAttribute(new Attribute("label", this.getLabel()));
		
		Element operation = new Element("operation");
		operation.appendChild(this.getOperation());
		e.appendChild(operation);
		
		for(ModelLinkFlowChartComponent m : this.connectedComponentsList){
			e.appendChild(m.getXML());
		}
		
		return e;
	}

	@Override
	public boolean addComponentConnection(ModelFlowChartComponent m) {
		this.connectedComponentsList.add(ModelChartFactory.createArrowComponent( this, m));
		this.fireModelChangeEvent();
		return false;
	}

	@Override
	public boolean setOperation(String operation) {
		
		if(validator.validateExpression(operation)){
			
			this.operation = operation;
			this.fireModelChangeEvent();
			return true;
		}else
			return false;
	}
}
